package com.github.natholdallas.database

import com.github.natholdallas.common.Gender
import com.github.natholdallas.common.OrderType
import com.github.natholdallas.common.Role
import jakarta.persistence.Column
import jakarta.persistence.ElementCollection
import jakarta.persistence.Entity
import jakarta.persistence.ManyToOne
import org.hibernate.annotations.OnDelete
import org.hibernate.annotations.OnDeleteAction
import java.math.BigDecimal

@Entity
class User(
    @Column(unique = true)
    var username: String = "",
    var password: String = "",
    var role: Role = Role.USER,
    var name: String? = null,
    var avatar: String? = null,

    // USER
    var amount: BigDecimal = BigDecimal.ZERO,
    var balance: BigDecimal = BigDecimal.ZERO,

    // COPILOT
    var description: String? = null,
    var gender: Gender = Gender.OTHER,
    var phone: String? = null,
    var qrcode: String? = null,
    var tag: String = ""
) : ILongIdRecordModel()


@Entity
class CommentTable(
    @ManyToOne @OnDelete(action = OnDeleteAction.CASCADE)
    var copilot: User = User(),
    @ManyToOne @OnDelete(action = OnDeleteAction.CASCADE)
    var user: User = User(),
    var content: String = ""
) : ILongIdRecordModel()


@Entity
class StarTable(
    @ManyToOne @OnDelete(action = OnDeleteAction.CASCADE)
    var copilot: User = User(),
    @ManyToOne @OnDelete(action = OnDeleteAction.CASCADE)
    var user: User = User(),
) : ILongIdRecordModel()


/**
 * @property user 老板
 * @property amount 金额
 * @property gift 代金券
 * @property payment 支付
 * @property amountRecord 截止本单充值
 * @property balanceRecord 截止本单余额
 */
@Entity
class TopupTable(
    @ManyToOne @OnDelete(action = OnDeleteAction.CASCADE)
    var user: User = User(),
    var description: String? = null,
    var amount: BigDecimal = BigDecimal.ZERO,
    var gift: BigDecimal = BigDecimal.ZERO,
    var payment: Boolean = false,
    var amountRecord: BigDecimal = BigDecimal.ZERO,
    var balanceRecord: BigDecimal = BigDecimal.ZERO
) : ILongIdRecordModel()


/**
 * @property user 老板
 * @property copilot 陪玩
 * @property description 订单详情
 * @property payment 已支付
 * @property type 订单类型
 * @property price 原价
 * @property duration 时长
 */
@Entity
class OrderTable(
    @ManyToOne @OnDelete(action = OnDeleteAction.CASCADE)
    var user: User = User(),
    @ManyToOne @OnDelete(action = OnDeleteAction.CASCADE)
    var copilot: User = User(),
    var description: String? = null,
    var payment: Boolean = false,
    var type: OrderType = OrderType.NONE,
    var price: Int = 0,
    var duration: Int = 0,
    var totalPrice: Int = 0,
    var iPrice: BigDecimal = BigDecimal.ZERO,
    var cPrice: BigDecimal = BigDecimal.ZERO,
    var amountRecord: BigDecimal = BigDecimal.ZERO,
    var balanceRecord: BigDecimal = BigDecimal.ZERO
) : ILongIdRecordModel()


/**
 * @property msg 消息
 */
@Entity
class LogTable(val msg: String = "") : ILongIdTableModel()
